package com.shop.loan.model;

import com.shop.loan.proxy.ChannelDataProxy;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_field.*;
import xyz.erupt.annotation.sub_field.sub_edit.BoolType;
import xyz.erupt.annotation.sub_field.sub_edit.ChoiceType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;
import xyz.erupt.annotation.sub_field.sub_edit.VL;
import xyz.erupt.upms.model.base.HyperModel;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;

@Erupt(name = "渠道", filter = @Filter("Channel.isDelete = false"), dataProxy = ChannelDataProxy.class)
@Table(name = "s_channel")
@SQLDelete(sql = "update r_channel set is_delete = true, delete_time = now() where id = ?")
@Entity
@Getter
@Setter
public class Channel extends HyperModel {


    @EruptField(
            views = @View(title = "名称"),
            edit = @Edit(title = "名称", notNull = true)
    )
    private String name;

    @EruptField(
            views = @View(title = "链接"),
            edit = @Edit(title = "链接", show = false)
    )
    private String url;

    @EruptField(
            views = @View(title = "邀请码"),
            edit = @Edit(title = "邀请码", readonly = @Readonly)
    )
    private String code;


    @Transient
    @EruptField(
            views = @View(title = "推广地址", type = ViewType.QR_CODE)
    )
    private String urlCode;

    @EruptField(
            views = @View(title = "单价"),
            edit = @Edit(title = "单价")
    )
    private BigDecimal unitPrice;

    @EruptField(
            views = @View(title = "备注"),
            edit = @Edit(title = "备注")
    )
    private String remark;

    @EruptField(
            views = @View(title = "已结算数量"),
            edit = @Edit(title = "已结算数量")
    )
    private Integer settleNum = 0;

    @EruptField(
            views = @View(title = "状态"),
            edit = @Edit(
                    title = "状态",
                    search = @Search,
                    type = EditType.BOOLEAN,
                    notNull = true,
                    boolType = @BoolType(
                            trueText = "正常",
                            falseText = "下线"
                    )
            )
    )
    private Boolean status = true;

    private Boolean isDelete = false;

    private Long productId;

    private Date deleteTime;


    public Channel(Long id) {
        setId(id);
    }

    public Channel() {
    }
}
